<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title data-i18n="resources.title_fastHeatMapLayer"></title>
    <style type="text/css">
        body {
            margin: 0;
            overflow: hidden;
            background: #fff;
            width: 100%;
            height: 100%
        }

        #map {
            position: absolute;
            width: 100%;
            height: 100%;
        }

        #toolbar {
            position: absolute;
            top: 50px;
            right: 10px;
            width: 300px;
            text-align: center;
            z-index: 100;
            border-radius: 4px;
        }
    </style>
</head>
<body>
<div id="toolbar" class="panel panel-primary">
    <div class='panel-heading'>
        <h5 class='panel-title text-center' data-i18n="resources.text_fastHeatMapLayer"></h5></div>
    <div class='panel-body content'>
        <div class='panel'>
            <div class='input-group'>
                <span class='input-group-addon' data-i18n="resources.text_countsDraw"></span>
                <input type='text' class='form-control' id='heatNums' value='200'/>
            </div>
        </div>
        <div class='panel'>
            <div class='input-group'>
                <span class='input-group-addon' data-i18n="resources.text_radius"></span>
                <input class='form-control' style='width: 50px' value='50' id='heatradius'/>
                <select class='form-control' style='width:auto' id='radiusUnit'>
                    <option value='px'>px</option>
                    <option data-i18n='[value]resources.text_degree;resources.text_degree'></option>
                </select>
            </div>
        </div>
        <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_startDraw"
               onclick="createHeatPoints()"/>&nbsp; &nbsp;
        <input type="button" class="btn btn-default" data-i18n="[value]resources.text_input_value_clear"
               onclick="clearHeatPoints()"/>
    </div>
</div>
<div id="map"></div>
<script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
<script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
<script>
    var host = window.isLocal ? window.server : "https://iserver.supermap.io";
    var map, layer, heatMapLayer,
        url = host + "/iserver/services/map-world/rest/maps/World";
    init();

    function init() {
        if (!document.createElement('canvas').getContext) {
            widgets.alert.showAlert(resources.msg_supportCanvas, false);
            return;
        }

        map = new SuperMap.Map("map", {
            controls: [
                new SuperMap.Control.ScaleLine(),
                new SuperMap.Control.Zoom(),
                new SuperMap.Control.Navigation({
                    dragPanOptions: {
                        enableKinetic: true
                    }
                })]
        });
        map.addControl(new SuperMap.Control.LayerSwitcher(), new SuperMap.Pixel(42, 80));
        map.addControl(new SuperMap.Control.MousePosition());
        layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", url, {
            transparent: true,
            cacheEnabled: true
        }, {maxResolution: "auto"});
        heatMapLayer = new SuperMap.Layer.HeatMapFastLayer(
            "heatMap",
            {
                "featureWeight": "value"
            }
        );
        layer.events.on({"layerInitialized": addLayer});
    }

    function addLayer() {
        map.addLayers([layer, heatMapLayer]);
        map.setCenter(new SuperMap.LonLat(0, 0), 0);
    }

    function createHeatPoints() {
        clearHeatPoints();
        var heatPoints = [];
        var num = parseInt(document.getElementById('heatNums').value);
        var radius = parseInt(document.getElementById('heatradius').value);
        var unit = document.getElementById("radiusUnit").value;
        heatMapLayer.useGeoUnit = false;
        //resources.text_degree 表示 id=radiusUnit 选项的第一选项值
        if (resources.text_degree == unit) {
            heatMapLayer.useGeoUnit = true;
        }
        heatMapLayer.radius = radius;
        heatMapLayer.maxWeight = 10;
        for (var i = 0; i < num; i++) {
            heatPoints[i] = new SuperMap.Feature.Vector(
                new SuperMap.Geometry.Point(
                    Math.random() * 360 - 180,
                    Math.random() * 180 - 90
                ),
                {
                    "value": Math.random() * 9
                }
            );
        }
        var t1 = new Date().getTime();
        heatMapLayer.addFeatures(heatPoints);
        var t2 = new Date().getTime();
        //console.info(num + "个总时间为：" + (t2-t1) + "ms");
        //alert(num + "个总时间为：" + (t2-t1) + "ms");
    }

    function clearHeatPoints() {
        heatMapLayer.removeAllFeatures();
    }

</script>
</body>
</html>